package svc

import (
	"github.com/bwmarrin/snowflake"
	_ "github.com/lib/pq"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"xialou_platform/services/order/model"
	"xialou_platform/services/order/rpc/internal/config"
)

type ServiceContext struct {
	Config     config.Config
	Flake      *snowflake.Node
	OrderModel model.OrderModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	conn := sqlx.NewSqlConn("postgres", c.Postgres.DataSource)
	flake, err := snowflake.NewNode(c.SnowflakeNode)
	if err != nil {
		panic(err)
	}
	return &ServiceContext{
		Config:     c,
		Flake:      flake,
		OrderModel: model.NewOrderModel(conn, c.CacheRedis),
	}
}
